//
//  WZPThemeModel.m
//  WZPItem
//
//  Created by 王王喆平 on 16/7/14.
//  Copyright © 2016年 UI. All rights reserved.
//

#import "WZPThemeModel.h"
#import "WZPThemeItem.h"
#import "WZPUserName.h"
#import "WZPCommentItem.h"

@implementation WZPThemeModel

-(void)setItem:(WZPThemeItem *)item{

    _item = item;
    // 设置间距
    CGFloat mangin = 10;
    CGFloat textY = 55;
    // 计算正文的frmae
    CGFloat textW = WZPScreenW - 2 * mangin;
    // 正文高度无限长  使用:constrainedToSize
    CGFloat textH = [item.text sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(textW, MAXFLOAT)].height;
    CGFloat topViewW = WZPScreenW;
    CGFloat topViewH = textY + textH;
    CGFloat topViewXY = 0;
    //
    _topViewFrame = CGRectMake(topViewXY, topViewXY, topViewW, topViewH);
    // 计算cell 高度
    _cellH = CGRectGetMaxY(_topViewFrame) + mangin;

    // 判断不是段子的时候,才需要计算
    // 计算中间ViewFrame(根据图片展示)
    // 判断非段子计算
    if (item.type != WZPThemeTypeText) {
        CGFloat midX = mangin;
        CGFloat midY = _cellH;
        CGFloat midW = textW;
        CGFloat midH = 0;
        if (item.width > 0) {
            midH = textW / item.width * item.height;
        }
        
        // 图片过大时进行操作
        if (midH > WZPScreenH) {
            midH = 300;
            // 对当前图片进行记录
            item.is_bigPicture = YES;
            
        }
        _midPictureViewFrame = CGRectMake(midX, midY, midW, midH);
        _cellH = CGRectGetMaxY(_midPictureViewFrame) + mangin;
    }

    if (item.commentView) {
        CGFloat commentX = mangin;
        CGFloat commentY = _cellH;
        CGFloat commentW = textW;
        CGFloat commentH = 42;
        if (item.commentView.content.length) {
            CGFloat textH = [item.commentView.totalCotent sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(commentW, MAXFLOAT)].height;
            commentH = 21 + textH;
        }
        _commentViewFrame = CGRectMake(commentX, commentY,commentW,commentH);
        _cellH = CGRectGetMaxY(_commentViewFrame) + mangin;
        
    }
    CGFloat btnX = 0;
    CGFloat btnY = _cellH;
    CGFloat btnW = WZPScreenW;
    CGFloat btnH = 35;
    _bottomViewFrame = CGRectMake(btnX, btnY, btnW, btnH);
    _cellH = CGRectGetMaxY(_bottomViewFrame);
    
}

@end
